﻿@{
    Layout = null;
}
@model Freshbox2._0.MODEL.supplier
<!DOCTYPE html>

<html>
<head>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="icon" type="image/gif" href="~/img/animated_favicon1.gif">
    <meta name="viewport" content="width=device-width" />
    <link href="~/UILibs/easyui/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/UILibs/easyui/themes/icon.css" rel="stylesheet" />
    <link href="~/Css/css.css" rel="stylesheet" />

    <script src="~/Scripts/jquery-1.7.1.min.js"></script>
    <script src="~/UILibs/easyui/jquery.easyui.min.js"></script>
    <script src="~/UILibs/easyui/locale/easyui-lang-zh_CN.js"></script>

    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
    <script src="~/Scripts/datagrid-detailview.js"></script>
    <title></title>
    <script type="text/javascript">
        $(function () {

            $('#storeids').combobox({
                valueField: "StoreID", //Value字段 
                textField: "StoreName", //Text字段         
                panelHeight: 'auto',
                multiple: true,
                dataType: "json",
                url: "/PancakeDis/GetStore", //数据源 
            });

            $("#data").datagrid({
                fit: true,
                title: '加盟商信息管理列表',
                striped: true,
                rownumbers: true,
                columns:
                    [[{
                        field: 'leagueid',
                        title: '编号',
                        width: 100,
                        height: 50,
                        halign: 'center',
                        sortable: true,
                        align: 'center'
                    }, {
                        field: 'leaguename',
                        title: '联系人姓名',
                        width: 100,
                        height: 50,
                        halign: 'center',
                        align: 'center',
                    }, {
                        field: 'leaguephone',
                        title: '手机号码（账号）',//leagueid  leaguename   leaguephone leaguesex leagueage  leagueemail leagueadress  leaguenumber registertime status storeids
                        width: 200,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'leaguepassword', 
                        title: '密码',
                        width: 200,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'leaguesex',
                        title: '性别',
                        width: 100,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'leagueage',
                        title: '年龄',
                        width: 100,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'leagueadress',
                        title: '地址',
                        width: 250,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'leaguenumber',
                        title: '身份证号码',
                        width: 200,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'registertime',
                        title: '注册时间',
                        width: 150,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'status',
                        title: '状态',
                        width: 100,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'storeids',
                        title: '管理的店铺',
                        width: 100,
                        height: 50,
                        hidden: true,
                        halign: 'center',
                        align: 'center'
                    }]],
                url: pageConfig.getAction,
                pagination: true,
                pageSize: 15,
                pageList: [15, 20, 25, 30],
                sortName: 'leagueid',
                sortOrder: 'desc',
                toolbar: '#tool'
            });
            $("#formdialog").dialog({
                width: 400,
                height: 350,
                closed: true,
                modal: true,
                buttons: '#btns'
            });

            $('#data').datagrid({
                view: detailview,
                detailFormatter: function (index, row) {
                    return '<div style="padding:12px"><table class="ddv"></table></div>';
                },
                onExpandRow: function (index, row) {
                    var ddv = $(this).datagrid('getRowDetail', index).find('table.ddv');
                    ddv.datagrid({
                        url: '/LeagueLogin/GetDetailStore',
                        fitColumns: true,
                        singleSelect: true,
                        rownumbers: true,
                        loadMsg: '',
                        height: 'auto',
                        columns: [[
                                {
                                    field: 'storeid',   //storeid    storeName    storeDress
                                    title: '店铺编号',
                                    width: 100,
                                    height: 50,
                                    halign: 'center',
                                    sortable: true,
                                    align: 'center'
                                }, {
                                    field: 'storeName',
                                    title: '店铺名称',
                                    width: 200,
                                    height: 50,
                                    halign: 'center',
                                    align: 'center',

                                }, {
                                    field: 'storeDress',
                                    title: '店铺地址',
                                    width: 250,
                                    height: 50,
                                    halign: 'center',
                                    align: 'center'
                                }, {
                                    field: 'property',
                                    title: '店铺属性',
                                    width: 150,
                                    height: 50,
                                    halign: 'center',
                                    align: 'center',
                                },
                        ]],
                        onResize: function () {
                            $('#data').datagrid('fixDetailRowHeight', index);
                        },
                        queryParams: {
                            storeids: row.storeids,
                        }
                    });
                    $('#data').datagrid('fixDetailRowHeight', index);
                }
            });


        });
        var pageConfig = {
            type: null,
            getAction: '@Url.Action("Get")',
            saveAction: '@Url.Action("Save")',
            delAction: '@Url.Action("ModifyState")',
            modifyAction: '@Url.Action("Modify")',
            getOneAction: '@Url.Action("GetOnlyOne")',
        };
                       
        //点击保存按钮 
        function save() {
            //leagueid   leaguename   leaguephone  leaguesex  leagueemail  password  storeids
            if ($("#leaguename").val() != null && $("#leaguename").val() != "" && $("#leaguephone").val() != null && $("#leaguephone").val() != "") {
                var bool = $("#fm").form("validate");
                if (bool) {
                    var rows = $("#data").datagrid("getSelections");
                    var data;
                    if (pageConfig.type == 1) {
                        url = pageConfig.saveAction;
                        data = {
                            leagueid: $("#formdialog input[name='leagueid']").val(),
                            leaguename: $("#leaguename").val(),
                            leaguephone: $("#leaguephone").val(),
                            leaguesex: $("#leaguesex").val(),
                            leaguepassword: $("#leaguepassword").val(),
                            leagueemail: $("#leagueemail").val(),
                            storeids: $("#storeids").val(),
                        };
                    }
                    else {
                        url = pageConfig.modifyAction;
                        data = {
                            leagueid: $("#leagueid").val(),
                            leaguename: $("#leaguename").val(),
                            leaguephone: $("#leaguephone").val(),
                            leaguesex: $("#leaguesex").val(),
                            leaguepassword: $("#leaguepassword").val(),
                            leagueemail: $("#leagueemail").val(),
                            storeids: $("#storeids").val(),
                        };
                    }
                    $.ajax({
                        url: url,
                        dataType: "json",
                        data: data,
                        type: "POST",
                        beforeSend: function () {
                            $.messager.progress({ title: "执行中", text: "" });
                        },
                        success: function (data) {
                            $.messager.alert("成功", data.msg, "info");
                        },
                        error: function (data) {
                            $.messager.alert("警告", "系统故障", "error", "")
                        },
                        complete: function () {

                            complete();
                        }
                    });

                }
            }
            else {
                $.messager.alert("用户名和密码不能为空", "用户名和密码不能为空", "info");
            }
        }

        //弹出框
        function alertFormDialog(type) {
            pageConfig.type = type;
            $("#formdialog form").form("reset");
            if (type == 1) {
                $("#formdialog").dialog("open");
                $("#formdialog").dialog("setTitle", "添加");
                $("#formdialog form").attr("action", pageConfig.saveAction);
            }
            else {
                var rows = $("#data").datagrid("getSelections");

                if (rows.length != 1) {
                    $.messager.alert("提示", "修改时必须且只能选中一条记录！", "info");
                }
                if (rows[0].status == 1) {
                    $.messager.alert("提示", "此用户已经被禁用！不能进行修改", "info");
                }
                else {

                    $("#formdialog").dialog("open");
                    $("#formdialog").dialog("setTitle", "修改"); 
                    //leagueid   leaguename   leaguephone  leaguesex  leagueemail  password  storeids
                    $.ajax({
                        async: false,
                        url: pageConfig.getOneAction + "?id=" + rows[0].leagueid,
                        dataType: "json",
                        type: "POST",
                        success: function (data) {
                            //alert(data.storeids);  可以穿过数字来
                            $("#leagueid").val(data.leagueid);
                            $("#leaguename").val(data.leaguename);
                            $("#leaguephone").val(data.leaguephone);
                            $("#leagueemail").val(data.leagueemail);
                            $("#leaguepassword").val(data.leaguepassword);
                            $("#storeids").combobox('setText', data.storeName);
                           // $("#storeids").combobox('setValue', data.storeids);//防止修改是 传不过值去                         
                            $("#leaguesex").combobox('setText', data.leaguesex);  //  赋值   完整的  赋值取值 传值过程 
                            $("#leaguesex").combobox('setValue', data.leaguesexID);//防止修改是 传不过值去
                        }
                    });
                }
            }
        }


        function closeDptDialog() {
            $("#formdialog").dialog("close")
        }
        ///禁用用户   状态改变
        function del() {

            var rows = $("#data").datagrid("getSelections")
            if (rows.length <= 0) {
                $.messager.alert("删除加盟商", "没有选中的行", "info");
                return;
            }

            $.messager.confirm("确定操作", "您确定要删除该加盟商吗？", function (flag) {
                if (flag) {
                    var idsStr = rows[0].leagueid;
                    $.ajax({
                        url: pageConfig.delAction,
                        data: { id: idsStr },
                        dataType: "json",
                        type: "POST",
                        beforeSend: function () {
                            before();
                        },
                        success: function (data) {
                            success(data);
                        },
                        error: function () {
                            error();
                        },
                        complete: function () {
                            complete();
                        }
                    });
                }
            })
        }



        function closeDptDialog() {
            $("#formdialog").dialog("close")
        }

        function searchData() {
            $("#data").datagrid('load', {
                leaguename: $("#txtName").val()

            });
        }

        function before() {
            $.messager.progress({ title: "执行中", text: "" });
        }

        function success(data) {
            $.messager.alert("成功", data.msg, "info");
        }
        function error() {

            $.messager.alert("警告", "系统故障", "error", "")
        }

        function complete() {
            $("#data").datagrid("load");
            $.messager.progress("close");
            $("#formdialog").dialog("close");
        }
    </script>
</head>
<body class="easyui-layout" style="width: 100%; height: 100%">
    <div data-options="region:'center'">
        <table id="data"></table>
        <div id="tool" style="padding: 10px;">
            <div style="margin-bottom: 10px;">
                <div style="margin-bottom: 10px;">
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    <a class="easyui-linkbutton" style="width: 100px; height: 50px;" iconcls="icon-add" onclick="alertFormDialog(1)">添加</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    <a class="easyui-linkbutton" style="width: 150px; height: 50px;" iconcls="icon-edit" onclick="alertFormDialog(2)">修改供应商信息</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    <a class="easyui-linkbutton" style="width: 100px; height: 50px;" iconcls="icon-remove" onclick="del()">删除供应商</a>
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    联系人姓名：<input id="txtName" style="width: 180px; height: 25px; margin-top: 15px" type="text" oninput="searchData()" />
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                <a class="easyui-linkbutton" style="width: 100px; height: 50px;" iconcls="icon-search" onclick="searchData()">查询</a>
                    <span style="font-size: larger; color: red">&nbsp&nbsp &nbsp&nbsp&nbsp   &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp   注意:可点击"+"号查看该加盟者旗下管理的店铺信息</span>
                </div>

            </div>
        </div>
    </div>

    <div id="formdialog">
        @using (Ajax.BeginForm(new AjaxOptions
        {
            OnBegin = "before",
            OnComplete = "complete",
            OnSuccess = "success",
            OnFailure = "error",
            HttpMethod = "Post"
        }))
        {   //leagueid   leaguename   leaguephone leaguesex  leagueemail  password  storeids
            <div class="dialog-table">
                <form id="fm" method="post">

                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tk_table">

                        <tr hidden="hidden">
                            <td>用户编号：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="leagueid" data-options="required:true" /></td>
                        </tr>
                        <tr>
                            <td>用户姓名：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="leaguename" data-options="required:true" /></td>
                        </tr>
                        <tr>
                            <td>手机号(账号)：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="leaguephone" data-options="required:true" /></td>
                        </tr>
                        <tr>
                            <td>密码：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" type="password" id="leaguepassword" data-options="required:true" /></td>
                        </tr>
                        <tr>
                            <td>邮箱：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="leagueemail" data-options="required:true" /></td>
                        </tr>
                        <tr>
                            <td>性别：</td>
                                   <td>              
                                <select id="leaguesex" class="easyui-combobox" name="leaguesex" style="width: 200px;">
                                    <option value="">请选择</option>
                                    <option value="0">男</option>
                                    <option value="1">女</option>

                                </select>
                                       </td>
                        </tr>
                        <tr>
                            <td>管理店铺：</td>
                            <td  class="white-tr">
                                <input id="storeids" class="easyui-combobox"  type="text" name="storeids" data-options="required:true" />
                            </td>
                        </tr>
                    </table>
                </form>
            </div>
        }
    </div>

    <div id="btns">
        <div style="margin-bottom: 10px">
            <a class="easyui-linkbutton" iconcls="icon-redo" onclick="closeDptDialog()">取消</a>
            <a class="easyui-linkbutton" iconcls="icon-add" onclick="save()">保存</a>
        </div>
    </div>
</body>
</html>
